public class MvcUriComponentsBuilder extends UriComponentsBuilder
Modifier and Type | Class and Description |
---|---|
private static class |
MvcUriComponentsBuilder.ControllerMethodInvocationInterceptor |
static interface |
MvcUriComponentsBuilder.MethodInvocationInfo |
Modifier and Type | Field and Description |
---|---|
private static CompositeUriComponentsContributor |
defaultUriComponentsContributor |
private static Log |
logger |
static java.lang.String |
MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME
Well-known name for the
CompositeUriComponentsContributor object in the bean factory. |
private static ObjenesisStd |
objenesis |
private static ParameterNameDiscoverer |
parameterNameDiscoverer |
private static PathMatcher |
pathMatcher |
Constructor and Description |
---|
MvcUriComponentsBuilder() |
Modifier and Type | Method and Description |
---|---|
private static UriComponents |
applyContributors(UriComponentsBuilder builder,
java.lang.reflect.Method method,
java.lang.Object[] args) |
static <T> T |
controller(java.lang.Class<T> controllerType)
Return a "mock" controller instance.
|
static UriComponentsBuilder |
fromController(java.lang.Class<?> controllerType)
Create a
UriComponentsBuilder from the mapping of a controller class
and current request information including Servlet mapping. |
static UriComponentsBuilder |
fromMethod(java.lang.reflect.Method method,
java.lang.Object... argumentValues)
Create a
UriComponentsBuilder from the mapping of a controller method
and an array of method argument values. |
static UriComponentsBuilder |
fromMethodCall(java.lang.Object invocationInfo)
Create a
UriComponentsBuilder by invoking a "mock" controller method. |
static UriComponentsBuilder |
fromMethodName(java.lang.Class<?> controllerType,
java.lang.String methodName,
java.lang.Object... argumentValues)
Create a
UriComponentsBuilder from the mapping of a controller method
and an array of method argument values. |
protected static CompositeUriComponentsContributor |
getConfiguredUriComponentsContributor() |
private static java.lang.reflect.Method |
getMethod(java.lang.Class<?> controllerType,
java.lang.String methodName,
java.lang.Object[] argumentValues) |
private static java.lang.String |
getMethodRequestMapping(java.lang.reflect.Method method) |
private static java.lang.String |
getTypeRequestMapping(java.lang.Class<?> controllerType) |
private static <T> T |
initProxy(java.lang.Class<?> type,
MvcUriComponentsBuilder.ControllerMethodInvocationInterceptor interceptor) |
static <T> T |
on(java.lang.Class<T> controllerType)
Return a "mock" controller instance.
|
build, build, buildAndExpand, buildAndExpand, fragment, fromHttpUrl, fromPath, fromUri, fromUriString, host, newInstance, path, pathSegment, port, query, queryParam, queryParams, replacePath, replaceQuery, replaceQueryParam, scheme, schemeSpecificPart, uri, uriComponents, userInfo
public static final java.lang.String MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME
CompositeUriComponentsContributor
object in the bean factory.private static final Log logger
private static final ObjenesisStd objenesis
private static final PathMatcher pathMatcher
private static final ParameterNameDiscoverer parameterNameDiscoverer
private static final CompositeUriComponentsContributor defaultUriComponentsContributor
public static UriComponentsBuilder fromController(java.lang.Class<?> controllerType)
UriComponentsBuilder
from the mapping of a controller class
and current request information including Servlet mapping. If the controller
contains multiple mappings, only the first one is used.controllerType
- the controller to build a URI fornull
private static java.lang.String getTypeRequestMapping(java.lang.Class<?> controllerType)
public static UriComponentsBuilder fromMethodName(java.lang.Class<?> controllerType, java.lang.String methodName, java.lang.Object... argumentValues)
UriComponentsBuilder
from the mapping of a controller method
and an array of method argument values. This method delegates to
fromMethod(java.lang.reflect.Method, Object...)
.controllerType
- the controllermethodName
- the method nameargumentValues
- the argument valuesnull
java.lang.IllegalStateException
- if there is no matching or more than
one matching method.private static java.lang.reflect.Method getMethod(java.lang.Class<?> controllerType, java.lang.String methodName, java.lang.Object[] argumentValues)
public static UriComponentsBuilder fromMethodCall(java.lang.Object invocationInfo)
UriComponentsBuilder
by invoking a "mock" controller method.
The controller method and the supplied argument values are then used to
delegate to fromMethod(java.lang.reflect.Method, Object...)
.
For example given this controller:
@RequestMapping("/people/{id}/addresses") class AddressController { @RequestMapping("/{country}") public HttpEntityA UriComponentsBuilder can be created:getAddressesForCountry(@PathVariable String country) { ... } @RequestMapping(value="/", method=RequestMethod.POST) public void addAddress(Address address) { ... } }
// Inline style with static import of "MvcUriComponentsBuilder.on" MvcUriComponentsBuilder.fromMethodCall( on(CustomerController.class).showAddresses("US")).buildAndExpand(1); // Longer form useful for repeated invocation (and void controller methods) CustomerController controller = MvcUriComponentsBuilder.on(CustomController.class); controller.addAddress(null); builder = MvcUriComponentsBuilder.fromMethodCall(controller); controller.getAddressesForCountry("US") builder = MvcUriComponentsBuilder.fromMethodCall(controller);
invocationInfo
- either the value returned from a "mock" controller
invocation or the "mock" controller itself after an invocationpublic static UriComponentsBuilder fromMethod(java.lang.reflect.Method method, java.lang.Object... argumentValues)
UriComponentsBuilder
from the mapping of a controller method
and an array of method argument values. The array of values must match the
signature of the controller method. Values for @RequestParam
and
@PathVariable
are used for building the URI (via implementations of
UriComponentsContributor
)
while remaining argument values are ignored and can be null
.method
- the controller methodargumentValues
- argument values for the controller methodnull
private static java.lang.String getMethodRequestMapping(java.lang.reflect.Method method)
private static UriComponents applyContributors(UriComponentsBuilder builder, java.lang.reflect.Method method, java.lang.Object[] args)
protected static CompositeUriComponentsContributor getConfiguredUriComponentsContributor()
public static <T> T on(java.lang.Class<T> controllerType)
@RequestMapping
method
on the controller is invoked, the supplied argument values are remembered
and the result can then be used to create a UriComponentsBuilder
via fromMethodCall(Object)
.
Note that this is a shorthand version of controller(Class)
intended
for inline use (with a static import), for example:
MvcUriComponentsBuilder.fromMethodCall(on(FooController.class).getFoo(1)).build();
controllerType
- the target controllerpublic static <T> T controller(java.lang.Class<T> controllerType)
@RequestMapping
method
on the controller is invoked, the supplied argument values are remembered
and the result can then be used to create UriComponentsBuilder
via
fromMethodCall(Object)
.
This is a longer version of on(Class)
. It is needed with controller
methods returning void as well for repeated invocations.
FooController fooController = controller(FooController.class); fooController.saveFoo(1, null); builder = MvcUriComponentsBuilder.fromMethodCall(fooController); fooController.saveFoo(2, null); builder = MvcUriComponentsBuilder.fromMethodCall(fooController);
controllerType
- the target controllerprivate static <T> T initProxy(java.lang.Class<?> type, MvcUriComponentsBuilder.ControllerMethodInvocationInterceptor interceptor)